package com.chanzany.factory.factoryMethod;

public abstract class PizzaFactory {
    static PizzaFactory factory;
    public static Pizza createPizza(String location, String orderType){
        if ("BJ".equals(location)) factory = new BJPizzaFactory();
        if ("LD".equals(location)) factory = new LDPizzaFactory();
        return factory.doCreatePizza(orderType);
    }
    //由各个工厂子类自己实现
    abstract Pizza doCreatePizza(String orderType);
}

class BJPizzaFactory extends PizzaFactory{
    @Override
    Pizza doCreatePizza(String orderType) {
        Pizza pizza;
        switch (orderType){
            case "cheese":
                pizza = new BJCheesePizza();
                pizza.setName("北京奶酪披萨");
                break;
            case "pepper":
                pizza = new BJPepperPizza();
                pizza.setName("北京胡椒披萨");
                break;
            default:
                throw new IllegalStateException("Unexpected value: " + orderType);
        }
        return pizza;
    }
}
class LDPizzaFactory extends PizzaFactory{
    @Override
    Pizza doCreatePizza(String orderType) {
        Pizza pizza;
        switch (orderType){
            case "cheese":
                pizza = new LDCheesePizza();
                pizza.setName("伦敦奶酪披萨");
                break;
            case "pepper":
                pizza = new LDPepperPizza();
                pizza.setName("伦敦胡椒披萨");
                break;
            default:
                throw new IllegalStateException("Unexpected value: " + orderType);
        }
        return pizza;
    }
}